using System;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;

namespace My.IdlConverter.Core.Filters
{
    public class InterfaceModifier
    {
        private static IFilterRule _filterRule;

        public static IList<string> ExcludeInterfaces = new List<string>();

        static InterfaceModifier()
        {
            ExcludeInterfaces.Add("Iv_DOMInnerInit");
            ExcludeInterfaces.Add("Iv_IdlConverterWrapper");
            ExcludeInterfaces.Add("Iv_DOMUndoRedoManager");
        }

        public static IFilterRule ActiveRule
        {
            get
            {
                return _filterRule;
            }
            set
            {
                _filterRule = value;
            }
        }

        public static bool IsDOMInterfaceName(string interfaceName)
        {
            if (Util.ArrayHelper.IndexOf<string>(ExcludeInterfaces, interfaceName.Trim()) != -1)
                return false;

            return (interfaceName.Trim().StartsWith("Iv_DOM"));
        }

        public static string GetName(string source)
        {
            string title = GetTitle(source);
            if (title.Length > 0)
                return "I" + title;

            return title;
        }

        public static string GetTitle(string source)
        {
            Debug.Assert(source != null);
            int pos = source.IndexOf("Iv_DOM");
            if (pos != -1)
            {
                string result = source.Replace("Iv_DOM", "").Trim();
                IFilterRule rule = ActiveRule;
                if (rule != null)
                {
                    return (rule.Filter(result));
                }
                return result;
            }
            else
            {
                Debug.Assert(false);
            }
            return "";
        }

        public static string GetVariable(Interface source)
        {
            return ("m_pIFDOM" + InterfaceModifier.GetTitle(source.Name));
        }
    }
}
